#pragma once
#include "GameObj.h"
#include <hgesprite.h>
#include <vector>

#define _TRACE_NOTARGET   0
#define _TRACE_TARGETING  1
#define _TRACE_TARGETDEAD 2

#define _BULLET_WEIGHT 0.3f
#define _BULLET_CITY 20

class BulletInfo : public GameObj
{
public:
	BulletInfo(hgeSprite* sprite,float x, float y, float vx, float vy, float rot,float pa, int type);
	virtual ~BulletInfo();
	virtual void Update();
	void Update(float tx,float ty);
	void Update(const char* funcname);
	virtual void Render();
	virtual hgeRect* getCollision(hgeRect* rect);
private:
	friend class BulletManager;
	friend class ScriptEngine;
	hgeSprite *m_sprite;   // sprite
	float m_x, m_y;			// pos
	float m_vx, m_vy;		// speed
	float m_rotation;			// rotation to render sprite
	int   m_type;			// type
	bool  m_clear;		// need be clear?
	int   m_behavType;	// lock bullet only
	float par,sx,sy,stime;			// just for script
};

class BulletManager
{
public:
	BulletManager();
	~BulletManager();
	
	void addBullet(BulletInfo *bullet);
	void delBullet(BulletInfo *bullet);
	void delBullet(int num);
	void LockTarget(float dx, float dy);
	void clearBulllet();
	void unLockTarget();
	void Update();
	void Render();
	int checkCollision(hgeRect *rect);
private:
	float m_targetX,m_targetY;
	std::vector<BulletInfo*> m_ves;
	inline void clearAll();
	inline void UpdateCheck(BulletInfo *bullet);
};